home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / toolbar / tbsrc / file3.bas < prev    next >
BASIC Source File  |  1994-10-09  |  29KB  |  747 lines

  1. Option Explicit
  2.  
  3. Type ToolType
  4.     Pos                     As apiRect      ' position on toolbar
  5.     nr                      As Integer      ' nr of tool
  6.     Group                   As Integer      ' group nr of tool
  7.     Visible                 As Integer      ' visible or not
  8.     Enabled                 As Integer      ' enabled or not
  9.     qHelp                   As Integer      ' use qHelp or not
  10.     StatText                As String       ' status text
  11.     MouseText               As String       ' qHelp text
  12.     UseMouse                As Integer      ' us mouse or not
  13.     CopyPicture             As Integer      ' copy picture or not
  14. End Type
  15. Dim mTools()                As ToolType
  16. Dim oTools()                As apiRect'ToolType
  17. Dim ToolSource()            As Control
  18. Dim TooloTarget()           As PictureBox
  19. Dim ToolcTarget()           As PictureBox
  20.  
  21. Dim ToolGroup               As Integer
  22. Dim ToolLeft                As Integer
  23. Dim qhloaded                As Integer
  24. Dim qhExit                  As Integer
  25. Dim Toolbar                 As PictureBox
  26. Global MDIParent            As Form
  27. Dim qHelp                   As Integer
  28. Dim FTTitle                 As String
  29. Dim FloatingToolbar         As Form
  30. Dim mOver                   As Integer
  31. Dim ToolCnt                 As Integer
  32. Dim lw                      As Integer
  33. Dim ToolMenu                As Control
  34. Dim UseFloatingTool         As Integer
  35. Dim lblstatus               As Label
  36. Dim cReady                  As String
  37. Global ChangeBar            As Integer
  38.  
  39. Global Const qhNoTool = -1
  40. Global Const qhNotUsed = -2
  41. Global Const qhNoBar = -3
  42. Global Const qhAppExit = -4
  43.  
  44. Declare Function GetCursor Lib "User" () As Integer
  45.  
  46. Sub vbQHCopyToolExt (TempTool As ToolType, nr As Integer, Source As Control, Target As PictureBox)
  47. Dim sosm As Integer, toar As Integer, lleft As Integer, rc As Integer
  48. Dim tRect As apiRect
  49.     If ToolGroup < TempTool.Group Then          ' check for new toolgroup
  50.     ToolGroup = TempTool.Group              ' if new toolgroup
  51.     ToolLeft = ToolLeft + 5                 ' space between tools
  52.     End If
  53.     mTools(nr).Pos.left = ToolLeft              ' copy position of tool
  54.     mTools(nr).Pos.top = 3
  55.     mTools(nr).Pos.right = Source.Width
  56.     mTools(nr).Pos.bottom = Source.Height
  57.     mTools(nr).nr = nr                          ' set toolnumber
  58.     mTools(nr).Group = TempTool.Group           ' set toolgroup
  59.     mTools(nr).Visible = TempTool.Visible       ' set toolprops
  60.     mTools(nr).Enabled = TempTool.Enabled
  61.     mTools(nr).qHelp = TempTool.qHelp
  62.     mTools(nr).StatText = TempTool.StatText     ' set stattext
  63.     mTools(nr).MouseText = TempTool.MouseText   ' set tooltext
  64.     mTools(nr).UseMouse = TempTool.UseMouse
  65.     mTools(nr).CopyPicture = TempTool.CopyPicture
  66.  
  67.     Set ToolSource(nr) = Source                 ' set source
  68.     Set TooloTarget(nr) = Target                ' set target
  69.     If mTools(nr).CopyPicture Then
  70.     Source.Parent.Source.Picture = Source.Picture
  71.     GetWindowRect Source.Parent.Source.hWnd, tRect            ' get source rect
  72.     
  73.     sosm = Source.Parent.ScaleMode              ' save prop
  74.     Source.Parent.ScaleMode = 3                 ' set new prop
  75.     toar = Target.AutoRedraw                    ' set props
  76.     Target.AutoRedraw = True
  77.                             ' copy tools image
  78.     rc = StretchBlt(Target.hDC, ToolLeft, 3, Source.Parent.Source.Width, Source.Parent.Source.Height, Source.Parent.Source.hDC, 0, 0, tRect.right - tRect.left, tRect.bottom - tRect.top, srcCopy)
  79.     
  80.     Target.Refresh
  81.     Target.Picture = Target.Image               ' set props
  82.     Target.AutoRedraw = toar
  83.     Source.Parent.ScaleMode = sosm
  84.     End If
  85.     ToolLeft = ToolLeft + Source.Width - 1
  86. End Sub
  87.  
  88. Sub vbQHelpExt (Target As PictureBox)
  89. Dim i As Integer, tn As Integer
  90. Dim tRect As apiRect, mRect As apiRect
  91. Dim mPos As apiPoint
  92.     If Not mOver Then                       ' if first time in function
  93.     mOver = True
  94.     GetWindowRect Target.hWnd, tRect    ' get toolbar rect
  95.     GetCursorPos mPos                   ' get and calc cursor position
  96.     mPos.X = mPos.X - tRect.left: mPos.Y = mPos.Y - tRect.top
  97.     i = vbQHGetToolNr(Target, mPos)         ' get active tool
  98.     If i = qhNoTool Then                ' invoke help
  99.         i = vbQHToolBarMove(Target)     ' move toolbar
  100.     Else
  101.         i = vbQHGetHelp(Target, i, qHelp)   ' get help
  102.     End If
  103.     If qhExit Then                      ' app closed
  104.         tn = qhAppExit
  105.     Else
  106.         tn = i                          ' toolnr
  107.     End If
  108. vbQHelpBreak:
  109.     vbQHTools tn
  110.     If Not qhExit Then                      ' app closed
  111.         lblstatus = cReady
  112.     End If
  113.     mOver = False
  114.     End If
  115. End Sub
  116.  
  117. Sub vbQHCalcToolPos (Target As PictureBox)
  118. Dim i As Integer, t As Integer, osm As Integer, oar As Integer, rc As Integer
  119. Dim tRect As apiRect
  120.     If Target.ScaleWidth = lw Then Exit Sub
  121.     lw = Target.ScaleWidth
  122.     osm = Target.ScaleMode
  123.     oar = Target.AutoRedraw
  124.     Target.ScaleMode = 3
  125.     Target.AutoRedraw = True
  126.     Target.Picture = LoadPicture("")
  127.     Target.Cls
  128.     ToolGroup = 0
  129.     ToolLeft = 0
  130.     t = 3'12
  131.     UseFloatingTool = True
  132.     For i = 0 To ToolCnt - 1
  133.     If TooloTarget(i) = Toolbar Then
  134.         If ToolGroup < mTools(i).Group Then         ' check for new toolgroup
  135.         ToolGroup = mTools(i).Group             ' if new toolgroup
  136.         ToolLeft = ToolLeft + 5                 ' space between tools
  137.         End If
  138.         ToolSource(i).Parent.Source.Picture = ToolSource(i).Picture
  139.         GetWindowRect ToolSource(i).Parent.Source.hWnd, tRect     ' get source rect
  140.                             ' copy tools image
  141.         If ToolLeft + ToolSource(i).Width > Target.ScaleWidth - 5 Then
  142.         t = t + ToolSource(i).Height + 5
  143.         ToolLeft = 5
  144.         End If
  145.         oTools(i).left = ToolLeft
  146.         oTools(i).top = t
  147.         oTools(i).right = ToolSource(i).Width
  148.         oTools(i).bottom = ToolSource(i).Height
  149.         rc = StretchBlt(Target.hDC, ToolLeft, t, ToolSource(i).Width, ToolSource(i).Height, ToolSource(i).Parent.Source.hDC, 0, 0, tRect.right - tRect.left, tRect.bottom - tRect.top, srcCopy)
  150.         ToolLeft = ToolLeft + ToolSource(i).Width - 1
  151.         Set ToolcTarget(i) = Target
  152.         If Not mTools(i).Enabled Then
  153.         mTools(i).Enabled = True
  154.         vbQHEnabled i, False
  155.         End If
  156.     End If
  157.     Next i
  158.     Target.ScaleMode = osm
  159.     Target.AutoRedraw = oar
  160. End Sub
  161.  
  162. Sub vbQHEnabled (MyTool As Integer, Flag As Integer)
  163. Dim oar As Integer
  164. Dim tRect As apiRect
  165. Dim pb As PictureBox
  166.     If mTools(MyTool).CopyPicture And mTools(MyTool).Enabled <> Flag Then ' if Picture is used
  167.     If UseFloatingTool Then         ' if tool is on floating toolbar
  168.         Set pb = ToolcTarget(MyTool)
  169.         tRect = oTools(MyTool)
  170.     Else                            ' if tool is on toolbar
  171.         Set pb = TooloTarget(MyTool)
  172.         tRect.left = mTools(MyTool).Pos.left
  173.         tRect.top = mTools(MyTool).Pos.top
  174.         tRect.right = mTools(MyTool).Pos.right
  175.         tRect.bottom = mTools(MyTool).Pos.bottom
  176.     End If
  177.     If Flag Then                    ' enable tool
  178.         vbQHMakeEnable tRect, pb, MyTool
  179.     Else
  180.         vbQHMakeDisable tRect, pb   ' disable tool
  181.     End If
  182.     If UseFloatingTool And Not ChangeBar Then         ' if tool is on floating toolbar
  183.         Set pb = TooloTarget(MyTool)
  184.         tRect.left = mTools(MyTool).Pos.left
  185.         tRect.top = mTools(MyTool).Pos.top
  186.         tRect.right = mTools(MyTool).Pos.right
  187.         tRect.bottom = mTools(MyTool).Pos.bottom
  188.         If Flag Then                    ' enable tool
  189.         vbQHMakeEnable tRect, pb, MyTool
  190.         Else
  191.         vbQHMakeDisable tRect, pb   ' disable tool
  192.         End If
  193.     End If
  194.     mTools(MyTool).Enabled = Flag
  195.     pb.Picture = pb.Image
  196.     End If
  197. End Sub
  198.  
  199. Sub vbQHExit (MyForm As Form)
  200. Dim i As Integer
  201. On Error Resume Next
  202.     Select Case MyForm.hWnd
  203.     Case MDIParent.hWnd
  204.         qhExit = True
  205.         For i = 0 To Forms.Count - 1
  206.         If Forms(i).hWnd <> MyForm.hWnd Then Unload Forms(i)
  207.         Next i
  208.     Case FloatingToolbar.hWnd
  209.         Unload ToolSource(0).Parent
  210.         SetChild MyForm.hWnd, MDIParent.hWnd, False
  211.         If Not Toolbar.Visible Then ToolMenu.Checked = False
  212.         UseFloatingTool = False
  213.     End Select
  214. End Sub
  215.  
  216. Sub vbQHFakeMove (MyForm As Form)
  217. Dim dc As Integer, l As Integer, t As Integer
  218. Dim cRect As apiRect, mRect As apiRect, lRect As apiRect
  219. Dim mPos As apiPoint, oldPos As apiPoint, oPoint As apiPoint
  220. Dim tRect As apiRect, dRect As apiRect
  221.     MP_Alt = Screen.MousePointer                ' save pointer
  222.     zGetInnerRect MDIParent, cRect              ' get mouse rect
  223.     cRect.bottom = cRect.top + MDIParent.ScaleHeight / Screen.TwipsPerPixelY + 1
  224.     If MyForm.MDIChild Then
  225.     ClipCursor cRect                            ' clip mouse region
  226.     End If
  227.     dc = CreateDC("DISPLAY", 0, 0, 0)           ' create dc
  228.     GetCursorPos mPos                           ' get mouse position
  229.     oldPos = mPos
  230.     GetWindowRect MyForm.hWnd, mRect            ' get rect to move
  231.     oPoint.X = mPos.X - mRect.left              ' get x offset
  232.     oPoint.Y = mPos.Y - mRect.top               ' get y offset
  233.     GetWindowRect Toolbar.hWnd, tRect           ' get rect, not to move
  234.     If Toolbar.Align = 1 Then
  235.     lRect.left = tRect.left
  236.     lRect.top = cRect.bottom - tRect.bottom + tRect.top
  237.     lRect.right = tRect.right
  238.     lRect.bottom = cRect.bottom
  239.     Else
  240.     lRect.left = tRect.left
  241.     lRect.top = cRect.top' - tRect.bottom + tRect.top
  242.     lRect.right = tRect.right
  243.     lRect.bottom = cRect.top + tRect.bottom - tRect.top
  244.     dRect = tRect
  245.     tRect = lRect
  246.     lRect = dRect
  247.     End If
  248.     dRect = mRect
  249.     DrawFocusRect dc, dRect                     ' draw rect
  250.     Do
  251.     DoEvents
  252.     Screen.MousePointer = 1                 ' set mousepointer
  253.     oldPos = mPos
  254.     GetCursorPos mPos                       ' get mouse position
  255.     If oldPos.X <> mPos.X Or oldPos.Y <> mPos.Y Then
  256.         DrawFocusRect dc, dRect             ' delete rect, calc new pos
  257.         mRect.left = mRect.left - oldPos.X + mPos.X
  258.         mRect.top = mRect.top - oldPos.Y + mPos.Y
  259.         mRect.right = mRect.right - oldPos.X + mPos.X
  260.         mRect.bottom = mRect.bottom - oldPos.Y + mPos.Y
  261.         If zisPointInRect(mPos, tRect) Then
  262.         dRect = tRect                   ' don't move in this rect
  263.         ElseIf zisPointInRect(mPos, lRect) Then
  264.         dRect = lRect                   ' don't move in this rect
  265.         Else
  266.         dRect = mRect                   ' move rect
  267.         End If
  268.         DrawFocusRect dc, dRect             ' draw rect
  269.     End If
  270.     Loop While GetKeyState(1) < 0               ' while mouse_down
  271.     DrawFocusRect dc, dRect                     ' delete rect
  272.     dc = DeleteDC(dc)                           ' delete dc
  273.     If MyForm.MDIChild Then
  274.     cRect.left = 0: cRect.right = GetSystemMetrics(0)
  275.     cRect.top = 0: cRect.bottom = GetSystemMetrics(1)
  276.     ClipCursor cRect                            ' clip mouse
  277.     End If
  278.     If zisPointInRect(mPos, tRect) Then          ' if mouse over toolbar
  279.     Toolbar.Align = 1
  280.     MakeStatusBar Toolbar
  281.     Toolbar.Visible = True                  ' show toolbar
  282.     Toolbar.Parent.Show
  283.     Unload MyForm                           ' hide form
  284.     ElseIf zisPointInRect(mPos, lRect) Then
  285.     Toolbar.Align = 2
  286.     MakeStatusBar Toolbar
  287.     Toolbar.Visible = True                  ' show toolbar
  288.     Toolbar.Parent.Show
  289.     Unload MyForm                           ' hide form
  290.     Else                                        ' else
  291.     MyForm.Cls                              ' clear form
  292.     If FloatingToolbar.MDIChild Then
  293.         l = mRect.left - MDIParent.Left / Screen.TwipsPerPixelX - GetSystemMetrics(32)
  294.         t = mRect.top - MDIParent.Top / Screen.TwipsPerPixelY - GetSystemMetrics(4) - GetSystemMetrics(15) - GetSystemMetrics(33)
  295.     Else
  296.         l = mPos.X - oPoint.X
  297.         t = mPos.Y - oPoint.Y
  298.     End If
  299.     MyForm.Move l * Screen.TwipsPerPixelX, t * Screen.TwipsPerPixelY        ' move form
  300.     End If
  301.     Screen.MousePointer = MP_Alt                ' restore old mousepointer
  302. End Sub
  303.  
  304. Private Function vbQHGetHelp (Target As Control, nr As Integer, qHelp As Integer) As Integer
  305. Dim ch As Integer, px As Integer, py As Integer, rc As Integer', qhTool As Integer
  306. Dim MouseState As Integer, fEnter As Integer, mDown As Integer
  307. Dim temp$
  308. Dim mPos As apiPoint, cExt As apiPoint
  309. Dim tRect As apiRect, aRect As apiRect, mRect As apiRect
  310. Dim wPoint As apiPoint, tPoint As apiPoint
  311. Dim StartTime As Single, StopTime As Single
  312. Dim sm As Integer, ds As Integer, dm As Integer, ar As Integer
  313.     GetWindowRect Target.hWnd, tRect        ' Position of Toolbars
  314.     vbQHGetHelp = qhNoTool                  ' Return value
  315.     fEnter = True                           ' just entered function
  316.     Do
  317. NewCursorPos:                               ' Mouse moved
  318.     GetCursorPos mPos                   ' Cursorposition
  319.     DoEvents                            ' relative position of mouse
  320.     If qhExit Then
  321.         If qhloaded Then                ' if QuickHelp is loaded
  322.         qhloaded = False            ' unload it
  323.         Unload wndQHelp
  324.         End If
  325.         Exit Function
  326.     End If
  327.     mPos.X = mPos.X - tRect.left: mPos.Y = mPos.Y - tRect.top
  328.                         ' if mouse is not over tool
  329.     If UseFloatingTool Then
  330.         mRect = oTools(nr)
  331.     Else
  332.         mRect = mTools(nr).Pos
  333.     End If                            'mTools(nr).Pos
  334.     If Not zisPointInRectExt(mPos, mRect) Then
  335.         nr = vbQHGetToolNr(Target, mPos)    ' get new tool
  336.         If nr = qhNoTool Then           ' if there is no new tool
  337.         Exit Do                     ' exit
  338.         Else                            ' else
  339.         If qhloaded Then            ' if QuickHelp is loaded
  340.             qhloaded = False        ' unload it
  341.             Unload wndQHelp
  342.         End If
  343.         WaitZehntel 2               ' wait on further movements
  344.         GoTo NewCursorPos           ' and start again
  345.         End If
  346.     End If
  347.     MouseState = GetKeyState(1)
  348.     If MouseState < 0 Then              ' if mouse_click
  349.         MouseState = True
  350.     Else
  351.         MouseState = False
  352.     End If
  353.     'If qhExit Then Exit Function
  354.     If MouseState Then                  ' if mouse_click
  355.                         ' write status text
  356.         If Len(mTools(nr).StatText) Then lblstatus.Caption = mTools(nr).StatText
  357.                         ' unload qHelp (if loaded)
  358.         If qhloaded Then Unload wndQHelp: qhloaded = False
  359.         sm = Target.ScaleMode           ' save old props
  360.         ds = Target.DrawStyle
  361.         dm = Target.DrawMode
  362.         ar = Target.AutoRedraw
  363.         Target.ScaleMode = 3            ' set new props
  364.         Target.DrawStyle = 0
  365.         Target.DrawMode = 13
  366.         Target.AutoRedraw = False
  367.         Target.Refresh
  368.         Do                              ' wait on mouse_up
  369.         GetCursorPos tPoint             ' get and calc cursor position
  370.         tPoint.X = tPoint.X - tRect.left: tPoint.Y = tPoint.Y - tRect.top
  371.         If zisPointInRectExt(tPoint, mRect) Then
  372.             If Not mDown Then
  373.                         ' perform mouse_click
  374.             rc = BitBlt(Target.hDC, mRect.left + 3, mRect.top + 3, mRect.right - 4, mRect.bottom - 4, Target.hDC, mRect.left + 2, mRect.top + 2, srcCopy)
  375.             Target.Line (mRect.left + 2, mRect.top + 2)-(mRect.left + mRect.right - 2, mRect.top + 2), RGB(192, 192, 192)
  376.             Target.Line (mRect.left + 2, mRect.top + 3)-(mRect.left + 2, mRect.top + mRect.bottom - 2), RGB(192, 192, 192)
  377.             Target.Line (mRect.left + 1, mRect.top + 1)-(mRect.left + 1, mRect.top + mRect.bottom - 2), RGB(128, 128, 128)
  378.             Target.Line (mRect.left + 1, mRect.top + 1)-(mRect.left + mRect.right - 2, mRect.top + 1), RGB(128, 128, 128)
  379.             Target.Line (mRect.left + 2, mRect.top + mRect.bottom - 2)-(mRect.left + mRect.right - 2, mRect.top + mRect.bottom - 2), RGB(192, 192, 192)'RGB(255, 255, 255)
  380.             Target.Line (mRect.left + mRect.right - 2, mRect.top + 2)-(mRect.left + mRect.right - 2, mRect.top + mRect.bottom - 1), RGB(192, 192, 192)'RGB(255, 255, 255)
  381.             mDown = True
  382.             End If
  383.         Else                        ' if mouse not over tool
  384.             If mDown Then Target.Refresh
  385.             mDown = False
  386.         End If
  387.         DoEvents
  388.         If qhExit Then Exit Function' if app closed
  389.         Loop While GetKeyState(1) < 0   ' mouse_up
  390.         Target.Refresh
  391.         Target.ScaleMode = sm           ' restore old props
  392.         Target.DrawStyle = ds
  393.         Target.DrawMode = dm
  394.         Target.AutoRedraw = ar
  395.         If mDown Then                   ' if tool clicked
  396.         vbQHGetHelp = nr            ' return toolnr
  397.         GoTo vbQHGetHelpBreak       ' break
  398.         End If
  399.     Else
  400.         If qHelp Then                       ' if user wants qHelp
  401.         If fEnter Then                  ' if just entered the function
  402.                         ' wait some time
  403.             StartTime = GetTickCount() / 1000
  404.             Do
  405.             StopTime = GetTickCount() / 1000
  406.             DoEvents
  407.                         ' if mouse_click start again
  408.             If GetKeyState(1) < 0 GoTo NewCursorPos
  409.             If qhExit Then Exit Function
  410.             If StartTime + (5 / 10) <= StopTime Then Exit Do
  411.             Loop
  412.             fEnter = False
  413.         End If
  414.         If Not qhloaded Then                ' if qHelp not loaded then
  415.             Load wndQHelp                ' load qHelp
  416.             temp$ = mTools(nr).MouseText    ' text for qHelp
  417.             rc = zvbGetCursorExt(cExt) - 1   ' Cursorheight
  418.             wndQHelp.CurrentX = 2
  419.             wndQHelp.CurrentY = 2
  420.             wndQHelp.Print temp$         ' write text, qhHeight, border
  421.             wndQHelp.Height = (wndQHelp.TextHeight(temp$) + 4) * Screen.TwipsPerPixelX
  422.             wndQHelp.Width = (wndQHelp.TextWidth(temp$) + 4) * Screen.TwipsPerPixelY
  423.             wndQHelp.Line (0, 0)-(wndQHelp.Width / Screen.TwipsPerPixelX - 1, wndQHelp.Height / Screen.TwipsPerPixelY - 1), , B
  424.             GetCursorPos wPoint
  425.                             ' calc position of window
  426.             px = wPoint.X - (wndQHelp.Width / Screen.TwipsPerPixelX) / 2 + cExt.X - 1
  427.             If px < 0 Then                  ' if left pos is negative
  428.             px = 0
  429.             ElseIf (px + wndQHelp.Width / Screen.TwipsPerPixelX) > GetSystemMetrics(0) Then
  430.                             ' if right border is not on screen
  431.             px = GetSystemMetrics(0) - wndQHelp.Width / Screen.TwipsPerPixelX
  432.             End If
  433.             py = (wPoint.Y + cExt.Y - 1)
  434.             If py + wndQHelp.Height / Screen.TwipsPerPixelY > GetSystemMetrics(1) Then
  435.                             ' if lower border is not on screen
  436.             py = wPoint.Y - 2 - wndQHelp.Height / Screen.TwipsPerPixelY
  437.             End If
  438.                             ' set new position of qHelp
  439.             wndQHelp.Move px * Screen.TwipsPerPixelX, Screen.TwipsPerPixelY * py
  440.             GetCursorPos tPoint             ' get and calc cursor position
  441.             tPoint.X = tPoint.X - tRect.left: tPoint.Y = tPoint.Y - tRect.top
  442.             If zisPointInRectExt(tPoint, mRect) Then
  443.                             ' if cursor is over tool
  444.             SetWindowPos wndQHelp.hWnd, -1, 0, 0, 0, 0, &H20 Or &H1 Or &H40 Or &H10 'Or &H8
  445.             Else                            ' if cursor is elsewhere
  446.             Unload wndQHelp
  447.             GoTo NewCursorPos           ' start again
  448.             End If
  449.             qhloaded = True                 ' qHelp loaded successful
  450.         End If  ' Not qhloaded
  451.         End If  ' qHelp
  452.     End If  ' MouseState
  453.     Loop
  454. vbQHGetHelpBreak:
  455.     Unload wndQHelp                              ' unload qHelp
  456.     qhloaded = False
  457. End Function
  458.  
  459. Private Function vbQHGetToolNr (Target As Control, tPos As apiPoint) As Integer
  460. Dim i As Integer
  461. Dim tRect As apiRect
  462.     vbQHGetToolNr = qhNoTool
  463.     For i = 0 To ToolCnt - 1        ' check every tool for rect and target
  464.     If UseFloatingTool Then
  465.         tRect = oTools(i)
  466.     Else
  467.         tRect = mTools(i).Pos
  468.     End If                         ' mTools(i).Pos
  469.     If zisPointInRectExt(tPos, tRect) Then
  470.         If Target = TooloTarget(i) Then
  471.         If mTools(i).Enabled Then
  472.             vbQHGetToolNr = i   ' return toolnr
  473.         End If
  474.         Exit For
  475.         ElseIf Target = ToolcTarget(i) Then
  476.         If mTools(i).Enabled Then
  477.             vbQHGetToolNr = i   ' return toolnr
  478.         End If
  479.         Exit For
  480.         End If
  481.     End If
  482.     Next i
  483. End Function
  484.  
  485. Sub vbQHInitTools (cnt As Integer, MyWnd As Form, Target As PictureBox, MyMenu As Control, status As Label, cap As String)
  486. Static Init As Integer
  487.     If Not Init Then
  488.     ToolCnt = cnt
  489.     ToolGroup = 0               ' init groups
  490.     ToolLeft = 0                ' init left
  491.     ReDim mTools(cnt - 1)       ' alloc memory for tools
  492.     ReDim oTools(cnt - 1)
  493.     ReDim ToolSource(cnt - 1)
  494.     ReDim TooloTarget(cnt - 1)
  495.     ReDim ToolcTarget(cnt - 1)
  496.     Set FloatingToolbar = MyWnd
  497.     Set Toolbar = Target                ' set props
  498.     Set MDIParent = Target.Parent
  499.     Set ToolMenu = MyMenu
  500.     Set lblstatus = status
  501.     Target.AutoRedraw = True
  502.     Target.BackColor = BUTTON_FACE
  503.     cReady = cap
  504.     Init = True                 ' init successful
  505.     End If
  506. End Sub
  507.  
  508. Private Sub vbQHMakeDisable (tRect As apiRect, Target As PictureBox)
  509. Dim i As Integer, j As Integer, k As Integer, l As Integer, m As Integer
  510. Dim lc As Long, dGrau As Long, hGrau As Long, Weiss As Long
  511. Dim osm As Integer
  512.     dGrau = RGB(128, 128, 128)
  513.     hGrau = RGB(192, 192, 192)
  514.     Weiss = RGB(255, 255, 255)
  515.     tRect.right = tRect.right + tRect.left
  516.     tRect.bottom = tRect.bottom + tRect.top
  517.     osm = Target.ScaleMode
  518.     Target.ScaleMode = 3
  519.     For i = tRect.left + 3 To tRect.right - 3
  520.     l = i: k = 0
  521.     For j = tRect.top + 3 To tRect.bottom - i - 1 + tRect.left
  522.         l = l + 1: lc = Target.Point(l, j)
  523.         Select Case lc
  524.         Case 0
  525.             Target.PSet (l, j), dGrau
  526.             If Target.Point(l + 1, j + 1) <> 0 Then k = True
  527.         Case Else
  528.             If k Then
  529.             If lc <> Weiss Then Target.PSet (l, j), Weiss
  530.             k = False
  531.             Else
  532.             If lc <> hGrau Then
  533.                 lc = hGrau: Target.PSet (l, j), lc
  534.             End If
  535.             End If
  536.         End Select
  537.     Next j
  538.     Next i
  539.     k = False
  540.     For i = tRect.top + 2 To tRect.bottom
  541.     'Stop
  542.     l = i: k = 0
  543.     For j = tRect.left + 3 To tRect.right - i - 4 + tRect.top
  544.         l = l + 1
  545.         lc = Target.Point(j, l)
  546.         Select Case lc
  547.         Case 0
  548.             Target.PSet (j, l), dGrau
  549.             If Target.Point(j + 1, l + 1) <> 0 Then k = True
  550.         Case Else
  551.             If k Then
  552.             If lc <> Weiss Then Target.PSet (j, l), Weiss
  553.             k = False
  554.             Else
  555.             If lc <> hGrau Then
  556.                 lc = hGrau: Target.PSet (j, l), lc
  557.             End If
  558.             End If
  559.         End Select
  560.     Next j
  561.     Next i
  562.     Target.ScaleMode = osm
  563. End Sub
  564.  
  565. Private Sub vbQHMakeEnable (tRect As apiRect, pb As PictureBox, ToolNr As Integer)
  566. Dim rc As Integer
  567.     ToolSource(ToolNr).Parent.Source.Picture = ToolSource(ToolNr)
  568.     rc = StretchBlt(pb.hDC, tRect.left, tRect.top, tRect.right, tRect.bottom, ToolSource(ToolNr).Parent.Source.hDC, 0, 0, tRect.right, tRect.bottom, srcCopy)
  569.     If Not UseFloatingTool Then
  570.     Unload ToolSource(ToolNr).Parent
  571.     End If
  572.     pb.Refresh
  573. End Sub
  574.  
  575. Sub vbQHShowTool ()
  576.     Unload FloatingToolbar      ' unload form
  577.     Toolbar.Visible = True      ' show toolbar
  578. End Sub
  579.  
  580. Function vbQHToolBarMove (Target As PictureBox) As Integer
  581. Dim i As Integer, g As Integer, h As Integer, t As Integer, l As Integer
  582. Dim wRect As apiRect, tRect As apiRect
  583. Dim mPos As apiPoint, tPos As apiPoint
  584.     vbQHToolBarMove = qhNoTool              ' return value
  585.     If Target = MDIParent.Toolbar Then
  586.     If GetKeyState(1) < 0 Then              ' if mouse_down
  587.         GetWindowRect Target.hWnd, wRect    ' get rect of toolbar
  588.         GetCursorPos mPos                   ' get mouse position
  589.         For i = 0 To ToolCnt - 1            ' on all tools
  590.         If TooloTarget(i) = Target Then ' if this target
  591.                         ' calc width of tools
  592.             tRect.right = tRect.right + mTools(i).Pos.right
  593.             If h < mTools(i).Pos.bottom Then h = mTools(i).Pos.bottom
  594.             If g < mTools(i).Group Then g = mTools(i).Group
  595.         End If
  596.         Next i
  597.         i = False
  598.         tRect.right = tRect.right + g * 5 + 2 * GetSystemMetrics(32)
  599.         tRect.bottom = h + 6 + 2 * GetSystemMetrics(33) + 8
  600.         Do
  601.         DoEvents
  602.         GetCursorPos mPos               ' get mouse position
  603.         If Not zisPointInRect(mPos, wRect) Then      ' mouse not over toolbar
  604.             If zvbQHToolFakeMove(tRect, Target) Then ' move form
  605.             GetCursorPos mPos                   ' get mouse position
  606.             If Not zisPointInRect(mPos, wRect) Then  ' mouse not over toolbar
  607.                 Target.Visible = False          ' hide toolbar
  608.                 lw = 0
  609.                 Load FloatingToolbar            ' load form
  610.                 FTTitle = FloatingToolbar.Tag
  611.                 If FloatingToolbar.MDIChild Then
  612.                 t = mPos.Y - GetSystemMetrics(4) - GetSystemMetrics(15) - Target.Parent.Top / Screen.TwipsPerPixelY - GetSystemMetrics(33)
  613.                 l = mPos.X - GetSystemMetrics(32) - Target.Parent.Left / Screen.TwipsPerPixelX
  614.                 Else
  615.                 t = mPos.Y
  616.                 l = mPos.X
  617.                 End If
  618.                 FloatingToolbar.Move l * Screen.TwipsPerPixelX, t * Screen.TwipsPerPixelY, tRect.right * Screen.TwipsPerPixelX, tRect.bottom * Screen.TwipsPerPixelY
  619.                 ChangeBar = True
  620.                 FloatingToolbar.Show
  621.                 'vbQHCalcToolPos FloatingToolbar ' copy tools and move form
  622.                 i = True
  623.             End If
  624.             End If
  625.         End If
  626.         Loop Until GetKeyState(1) >= 0      ' mouse_up
  627.     End If
  628.     End If
  629. End Function
  630.  
  631. Private Sub vbQHTools (nr As Integer)
  632.     Select Case nr
  633.     Case qhAppExit
  634.         Exit Sub
  635.     Case qhNoBar
  636.         ' nop
  637.     Case qhNotUsed
  638.         ' nop
  639.     Case qhNoTool
  640.         lblstatus.Caption = cReady
  641.     Case Else
  642.         ToolCalled nr, lblstatus
  643.     End Select
  644. End Sub
  645.  
  646. Sub vbQHUsed (ByVal Flag As Integer)
  647.     qHelp = Flag
  648. End Sub
  649.  
  650. Private Function zisPointInRect (MyPoint As apiPoint, MyRect As apiRect) As Integer
  651.     If MyPoint.X > MyRect.left And MyPoint.X < MyRect.right And MyPoint.Y > MyRect.top And MyPoint.Y < MyRect.bottom Then zisPointInRect = True
  652. End Function
  653.  
  654. Private Function zisPointInRectExt (MyPoint As apiPoint, MyRect As apiRect) As Integer
  655.     If MyPoint.X > MyRect.left And MyPoint.X < MyRect.right + MyRect.left And MyPoint.Y > MyRect.top And MyPoint.Y < MyRect.bottom + MyRect.top Then zisPointInRectExt = True
  656. End Function
  657.  
  658. Private Function zvbGetCursorExt (cPoint As apiPoint) As Integer
  659. Dim hCur As Integer, rc As Integer
  660. Dim hsx As Integer, hsy As Integer
  661.     hCur = GetCursor()                          ' get cursor
  662.     rc = DrawIcon(wndQHelp.hDC, 0, 0, hCur)  ' copy cursor
  663.     wndQHelp.Refresh
  664.     For hsy = GetSystemMetrics(14) To 1 Step -1 ' get x,y ext of cursor
  665.     For hsx = GetSystemMetrics(13) To 1 Step -1
  666.         If wndQHelp.Point(hsx, hsy) = 0 Then
  667.         cPoint.Y = hsy                  ' return x and y
  668.         cPoint.X = hsx
  669.         zvbGetCursorExt = True
  670.         GoTo vbGetCursorExtExit         ' exit sub
  671.         End If
  672.         'vbQHelpForm.PSet (hsx, hsy)
  673.     Next hsx
  674.     Next hsy
  675. vbGetCursorExtExit:
  676.     wndQHelp.Cls                             ' clear form
  677. End Function
  678.  
  679. Private Function zvbQHToolFakeMove (fRect As apiRect, Target As PictureBox) As Integer
  680. Dim dc As Integer, dx As Integer, dy As Integer, X As Integer, Y As Integer
  681. Dim status As Integer
  682. Dim mPos As apiPoint, oldPos As apiPoint
  683. Dim mRect As apiRect, wRect As apiRect, lRect As apiRect, cRect As apiRect
  684.     MP_Alt = Screen.MousePointer        ' store cursor
  685.     status = True
  686.     GetWindowRect Target.hWnd, wRect
  687.     zGetInnerRect Target.Parent, cRect
  688.     cRect.bottom = cRect.top + Target.Parent.ScaleHeight / Screen.TwipsPerPixelY + 1
  689.     If Target.Align = 1 Then
  690.     lRect.left = wRect.left
  691.     lRect.top = cRect.bottom' - 10' - wRect.bottom + wRect.top
  692.     lRect.right = wRect.right
  693.     lRect.bottom = cRect.bottom + wRect.bottom - wRect.top
  694.     Else
  695.     lRect.left = wRect.left
  696.     lRect.top = cRect.top
  697.     lRect.right = wRect.right
  698.     lRect.bottom = cRect.top + wRect.bottom - wRect.top
  699.     mRect = wRect
  700.     wRect = lRect
  701.     lRect = mRect
  702.     End If
  703.     Screen.MousePointer = 1             ' set cursor
  704.     dc = CreateDC("DISPLAY", 0, 0, 0)   ' create dc
  705.     GetCursorPos mPos                   ' get mouse position
  706.     oldPos = mPos
  707.     mRect.left = fRect.left + mPos.X    ' calc new draw rect
  708.     mRect.top = fRect.top + mPos.Y
  709.     mRect.right = fRect.right + mPos.X
  710.     mRect.bottom = fRect.bottom + mPos.Y
  711.     DrawFocusRect dc, mRect             ' draw rect
  712.     Do
  713.     DoEvents
  714.     Screen.MousePointer = 1         ' set cursor
  715.     oldPos = mPos
  716.     GetCursorPos mPos               ' get mouse position, if changed
  717.     If oldPos.X <> mPos.X Or oldPos.Y <> mPos.Y Then
  718.         DrawFocusRect dc, mRect     ' clear old rect
  719.         If zisPointInRect(mPos, wRect) Then
  720.         mRect = wRect           ' set rect not to move
  721.         ElseIf zisPointInRect(mPos, lRect) Then
  722.         mRect = lRect           ' set rect not to move
  723.         Else
  724.         mRect.left = fRect.left + mPos.X    ' calc new rect
  725.         mRect.top = fRect.top + mPos.Y
  726.         mRect.right = fRect.right + mPos.X
  727.         mRect.bottom = fRect.bottom + mPos.Y
  728.         End If
  729.         DrawFocusRect dc, mRect     ' draw new rect
  730.     End If
  731.     Loop While GetKeyState(1) < 0       ' mouse_up
  732.     DrawFocusRect dc, mRect             ' clear old rect
  733.     dc = DeleteDC(dc)                   ' delete dc
  734.     If zisPointInRect(mPos, wRect) Then
  735.     Target.Align = 1
  736.     status = False
  737.     MakeStatusBar Target
  738.     ElseIf zisPointInRect(mPos, lRect) Then
  739.     Target.Align = 2
  740.     status = False
  741.     MakeStatusBar Target
  742.     End If
  743.     zvbQHToolFakeMove = status
  744.     Screen.MousePointer = MP_Alt        ' restore cursor
  745. End Function
  746.  
  747.